//
//  HttpClient.h
//  ITV
//
//  Created by inphase on 17/4/5.
//  Copyright © 2017年 inphase. All rights reserved.
//

#import <Foundation/Foundation.h>

#if __has_include(<AFNetworking.h>)
#import <AFNetworking.h>
#else
#import "AFNetworking.h"
#endif


#import "HttpClientHeader.h"

#import "DefaultResponseHandler.h"
#import "DefaultParameterHandler.h"
#import "DefaultURLHandler.h"




#define HC_DEPRECATED(explain) __attribute__((deprecated(explain)))


@interface HttpClient : NSObject<NSCopying>

@property (nonatomic,strong) AFHTTPSessionManager *manager;
@property (nonatomic,strong) AFHTTPResponseSerializer *responseSerializer;
@property (nonatomic,strong) AFHTTPRequestSerializer *requestSerializer;

@property (nonatomic,strong) NSURLSessionTask *sessionTask;

@property (nonatomic,assign) NSStringEncoding stringEncoding;
@property (nonatomic,assign) NSTimeInterval timeoutInterval;



/*
 * 在默认处理的基础上进行重写
 * 可以继承默认实现，然后修改
 * 也可以实现接口，实现对应方法
 * 通过设置实现类的 Class修改实现方式
 */
@property (nonatomic,strong) DefaultURLHandler *urlHandler;
@property (nonatomic,strong) DefaultParameterHandler *parameterHandler;
@property (nonatomic,strong) DefaultResponseHandler *responseHandler;

+(void) setDefaultResponseHandlerClass:(Class) classType;
+(void) setDefaultParameterHandlerClass:(Class) classType;
+(void) setDefaultURLHandlerClass:(Class) classType;

/*
 * 对处理完全重写
 * 一般用于需要特殊处理的地方
 * 此种方式会覆盖默认实现（实现此方法后会忽略默认实现）
 */
@property (nonatomic,strong) id <HttpClientParameterDelegate> parameterDelegate;
@property (nonatomic,strong) id <HttpClientResponseDelegate> responseDelegate;
@property (nonatomic,strong) id <HttpClientURLDelegate> urlDelegate;


/**
 @api {工厂方法} +(HttpClient*)httpClient 实例方法
 @apiName client
 @apiDescription 创建HttpClient实例的工厂方法
 @apiGroup HttpClient
 @apiExample  示例代码
 HttpClient *httpClient = [HttpClient client];
 */
+(HttpClient*) client;

// 取消网络请求
-(void) cancel;


/**
 @api {POST} POST:parameters:responseClass:success:failure 带返回对象的Post请求
 @apiName 带返回对象的Post请求
 @apiDescription 带返回对象的Post方式Http请求
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */
-(NSURLSessionTask *) POST:(NSString*) url
                    parameters:(id) parameters
                 responseClass:(Class) classType
                       success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                       failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

-(NSURLSessionTask *) POST:(NSString*) url
                parameters:(id) parameters
                    header:(NSDictionary *) header
             responseClass:(Class) classType
                   success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                   failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

/**
 @api {GET} GET:parameters:responseClass:success:failure 带返回对象的GET请求
 @apiName 带返回对象的GET请求
 @apiDescription 带返回对象的GET方式Http请求
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */

-(NSURLSessionTask *) GET:(NSString*) url
                   parameters:(id) parameters
                responseClass:(Class) classType
                      success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                      failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

-(NSURLSessionTask *) GET:(NSString*) url
                parameters:(id) parameters
                    header:(NSDictionary *) header
             responseClass:(Class) classType
                   success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                   failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

/**
 @api {POST} POSTWithToken:parameters:responseClass:success:failure 传递Token的Post请求
 @apiName 传递Token的Post请求
 @apiDescription 带返回对象的Post方式Http请求,这种请求会把Token传递给服务器，需实现TokenDelegate中的方法
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */
-(NSURLSessionTask *) POSTWithToken:(NSString*) url
                             parameters:(id) parameters
                          responseClass:(Class) classType
                                success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                                failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure HC_DEPRECATED("1.0.3");

/**
 @api {GET} GETWithToken:parameters:responseClass:success:failure 传递Token的GET请求
 @apiName 传递Token的GET请求
 @apiDescription 带返回对象的Post方式Http请求,这种请求会把Token传递给服务器，需实现TokenDelegate中的方法
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */
-(NSURLSessionTask *) GETWithToken:(NSString*) url
                            parameters:(id) parameters
                         responseClass:(Class) classType
                               success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                               failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure HC_DEPRECATED("1.0.3");


/**
 @api {GET} GET:parameters:responseClass:success:failure 普通的GET请求
 @apiName 不带返回对象的GET请求
 @apiDescription 普通的Get方式Http请求
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */
- (NSURLSessionTask *)GET:(NSString *)URLString
               parameters:(id)parameters
                  success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                  failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;
- (NSURLSessionTask *)GET:(NSString *)URLString
               parameters:(id)parameters
                   header:(NSDictionary *) header
                  success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                  failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;
/**
 @api {POST} POST:parameters:responseClass:success:failure 普通的Post请求
 @apiName 普通的Post请求
 @apiDescription 带返回对象的Post方式Http请求
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */
- (NSURLSessionTask *)POST:(NSString *)URLString
                parameters:(id)parameters
                   success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                   failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

- (NSURLSessionTask *)POST:(NSString *)URLString
                parameters:(id)parameters
                    header:(NSDictionary *) header
                   success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                   failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure;

/**
 @api {GET} GETWithToken:parameters:responseClass:success:failure 普通的传递Token的GET请求
 @apiName 普通的传递Token的GET请求
 @apiDescription 带返回对象的Post方式Http请求,这种请求会把Token传递给服务器，需实现TokenDelegate中的方法
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */
- (NSURLSessionTask *)GETWithToken:(NSString *)URLString
                            parameters:(id)parameters
                               success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                               failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure HC_DEPRECATED("1.0.3");
/**
 @api {POST} POSTWithToken:parameters:responseClass:success:failure 普通的传递Token的Post请求
 @apiName 普通的传递Token的Post请求
 @apiDescription 带返回对象的Post方式Http请求,这种请求会把Token传递给服务器，需实现TokenDelegate中的方法
 @apiGroup HttpClient
 @apiParam {String} url 请求的地址（全路径）
 @apiParam {Dictionary} parameters 请求的参数
 @apiParam {Class} classType 返回的Model类型
 @apiParam {SuccessBlock} success 请求成功的回调
 @apiParam {FailureBlock} failure 请求失败的回调
 @apiSampleRequest http://localhost/user.ac/
 */
- (NSURLSessionTask *)POSTWithToken:(NSString *)URLString
                             parameters:(id)parameters
                                success:(void (^)(NSURLSessionTask *operation, id responseObject))success
                                failure:(void (^)(NSURLSessionTask *operation, NSError *error))failure HC_DEPRECATED("1.0.3");


@end
